<template>
	<view>
		<!-- 头部栏 -->
		<u-sticky bgColor="#fff">
			<view class="bgw">
				<!-- <view class="search">
				<u-input placeholder="请输入单号" border="surround" v-model="value"
					:customStyle="{backgroundColor:'#e5e5e5'}" ></u-input>
				<button class="search_button">搜索</button>
			</view> -->
				<u-tabs :itemStyle="{ fontSize: '28rpx' }" :scrollable="false" :current="current" :list="list"
					@click="clickTab"></u-tabs>
			</view>
		</u-sticky>
		<!-- 订单列表 -->
		<view class="order_list">
			<view class="order_item" v-for="(item, index) in orderList" :key="index">
				<view class="info">
					<view class="name">
						<image src="https://mg-print.oss-cn-shenzhen.aliyuncs.com/img/store.png" mode=""></image>
						<text style="flex: 1;">{{ item.ShopName || '文库购买' }}</text>
					</view>
					<text class="status">{{ item.ShopName ? item.Type : '' }}</text>
				</view>
				<view class="order_num">
					<text>订单号：{{ item.OrderNo }}</text>
					<view class="order_time">
						<text>下单时间：{{ returnTime(item.OrderTime) }}</text>
						<text> 实付：￥{{ item.Price }}</text>
					</view>
					<view class="order_time" v-if="item.RefundPrice>0">
						<text>退款金额</text>
						<text style="color:#FC201C;">￥{{ item.RefundPrice }}</text>
					</view>
					<view class="order_time" v-if="item.IsRefund">
						<view class="refBtn" @click="applyRef(item)">退款</view>
					</view>
				</view>

			</view>
		</view>
		<pageEmpty v-if="orderList.length == 0" text="暂无订单哦~"></pageEmpty>
	</view>
</template>

<script>
import pageEmpty from '@/components/pageEmpty/pageEmpty'
export default {
	options: {
		styleIsolation: 'shared'
	},
	components: {
		pageEmpty
	},
	data() {
		return {
			value: '',
			list: [{
				name: '全部订单',
				type: 'All'
			},
			// {
			// 	name: '待付款',
			// 	type: 'Obligation'
			// },
			{
				name: '待打印',
				type: 'PExecution'
			}, {
				name: '已打印',
				type: 'Paid'
			},
			],
			pageSize: 10,
			pageIndex: 1,
			type: 'All',
			orderList: [],
			current: 0,
		};
	},
	onLoad(option) {
		this.type = option.type || 'All'
		for (let i = 0; i < this.list.length; i++) {
			if (this.type == this.list[i].type) {
				this.current = i
			}

		}
		this.getList()

	},
	methods: {
		clickTab(e) {
			console.log(e);
			this.type = e.type
			this.orderList = []
			this.pageIndex = 1
			this.getList()
		},
		async getList() {
			let res = await this.$api.post('MLogin/GetUserPrintOrder', {
				Type: this.type,
				PageNumber: this.pageIndex,
				PageSize: this.pageSize
			})
			this.orderList = [...this.orderList, ...res.data]
		},
		returnTime(time) {
			return time.replace('T', ' ')
		},
		// 退款
		async refund(item) {
			let res = await this.$api.post('Polymerization/PayRefund', {
				OrderNo: item.OrderNo
			})
			if (res?.code == 0) {
				this.$pv.msg('退款成功')
				this.orderList = []
				this.pageIndex = 1
				this.getList()
			} else {
				this.$pv.msg(res?.message)
			}
		},
		// 点击退款按钮
		applyRef(item){
			let that = this
			uni.showModal({
				title: '提示',
				content: `确定将"${item.OrderNo}"订单申请退款吗`,
				success: async function (res) {
					if (res.confirm) {
						that.refund(item)
					}

				}
			});
		}
	},
	onReachBottom() {
		this.pageIndex += 1
		this.getList()
	},

}
</script>
<style>
page {
	background-color: #f5f5f5;
}
</style>

<style lang="scss" scoped>
.status {
	font-size: 28rpx;
	min-width: 110rpx;
	text-align: right;
}

.order_time {
	display: flex;
	justify-content: space-between;
	align-items: center;

	.refBtn {
		border-radius: 28rpx;
		border: 2rpx solid #D2D2D2;
		font-weight: 500;
		font-size: 24rpx;
		color: #333333;
		padding: 12rpx 32rpx;
		margin-top: 20rpx;
		margin-left: auto;
	}
}

.order_num {
	font-size: 26rpx;
	display: flex;
	flex-direction: column;
	// height: 150rpx;
	padding: 20rpx;
	justify-content: space-between;
}

.order_list {
	.order_item {
		margin-bottom: 20rpx;
		background-color: #ffffff;
		color: #888888;

		.name {
			display: flex;
			align-items: center;

			image {
				width: 40rpx;
				height: 40rpx;
				margin-right: 10rpx;
			}
		}

		.info {
			padding: 20rpx;
			display: flex;
			justify-content: space-between;
			// height: 100rpx;
			border-bottom: 1rpx solid #f8f8f8;
			// align-items: center;
		}

		display: flex;
		flex-direction: column;

	}

	margin-top: 20rpx;
	display: flex;
	flex-direction: column;
}

::v-deep .u-tabs__wrapper__nav__item__text {
	font-size: 26rpx !important;
}

::v-deep .u-tabs__wrapper__nav {
	height: 100rpx;
}

::v-deep .u-tabs__wrapper__nav__line {
	bottom: 0 !important;
}

.bgw {
	background-color: white;
	padding-top: 20rpx;
}

.search {
	.search_button {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 140rpx;
		background-color: #ffffff;
		font-size: 26rpx;
		color: #787878;
	}

	display: flex;
	padding: 0 20rpx;
	margin-bottom: 20rpx;
}
</style>